package com.scst.service.impl;

import com.scst.entity.WrongTopic;
import com.scst.mapper.WrongTopicMapper;
import com.scst.service.ReportService;
import com.scst.vo.TopicReportVo;
import org.apache.tomcat.util.buf.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    WrongTopicMapper wrongTopicMapper;

    @Override
    public TopicReportVo getTopicStatistics(LocalDate begin, LocalDate end) {
        List<LocalDate> dateList = new ArrayList<>();
        dateList.add(begin);
        while (!begin.equals(end)) {
            begin = begin.plusDays(1);
            dateList.add(begin);
        }
        List<Double> turnList = new ArrayList<>();
        for (LocalDate date : dateList) {
            //查询date日期的错题数据，科目为语文或数学或其他科目的数据
            LocalDateTime beginTime = LocalDateTime.of(date, LocalTime.MIN);
            LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);
            Map map=new HashMap<>();
            map.put("begin",beginTime );
            map.put("end",endTime);
            map.put("subjects", WrongTopic.CHINESE);
            Double topicReport=wrongTopicMapper.sumBymap(map);
        }
        return TopicReportVo
                .builder()
                .dateList(LocalDateTime.parse(StringUtils.join(Collections.singleton(String.valueOf(dateList)), '，')))
                .topicList(StringUtils.join(Collections.singleton(String.valueOf(turnList)), ','))
                .build();
    }

    @Override
    public TopicReportVo getMathTopicStatistics(LocalDate begin, LocalDate end) {
        return null;
    }
}
